//
// Created by xili on 2024/8/28 20:40.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution1 {
public:
    bool isValid(string s) {
        string need = "cba";
        stack<char> st;
        for (auto &item: s) {
            st.push(item);
            if (st.size() >= 3 && st.top() == 'c') {
                string cur = "";
                int cnt = 3;
                while (cnt--) {
                    cur += st.top();
                    st.pop();
                }
                if (cur != need) {
                    return false;
                }
            }
        }
        return st.empty();
    }
};

class Solution2 {
public:
    bool isValid(string s) {
        int c;
        while ((c = s.find("abc")) != string::npos) {
            s.erase(c, 3);
        }
        return s.empty();
    }
};